package satirGame;

import java.io.*;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class SayActEvent extends Event {
	private static String[] qType={"Say","Action"};
	private int type;
	public SayActEvent(int t) { 
        super(); 
        type=t;
    } 
	
	public void loadQuestion(JFrame gameFrame) throws FileNotFoundException {
		String strFromFile = null;
		int count = 0;
		try {
			FileReader fr=new FileReader(String.valueOf(type)+".txt");
			BufferedReader bfr=new BufferedReader(fr);
			 //read each question and stop at new question not yet used
			while ((strFromFile=bfr.readLine())!=null && count<newQuestionIndex) {
				count++;
			}
			newQuestionIndex++; //index of new question point to next line of the database
			
			//set question and option for Event type 0 and 1
				setEventquestion(strFromFile);
				System.out.println(strFromFile);
				options = new Object[]{"Bad","Normal","Good"};
			
			for(Object name:options){
				System.out.println(name);
			}
			System.out.println((count+1)+" lines read");
			if((strFromFile=bfr.readLine())==null){
				newQuestionIndex=0;
			}
        }catch(ArrayIndexOutOfBoundsException e) {
            System.out.println("File not found");//if file not found
        }catch(IOException e) { 
            e.printStackTrace(); 
        }
		QuestionDialog(gameFrame);
    }
	
	public void QuestionDialog(JFrame gameFrame) throws FileNotFoundException{
		String eventQuestion =(getEventquestion()+"，之後請他評分");
		
		int initscore = JOptionPane.showOptionDialog(gameFrame,
				eventQuestion,
				qType[type],
				JOptionPane.YES_NO_OPTION,
				JOptionPane.QUESTION_MESSAGE,
				null,     //do not use a custom Icon
				options,  //the titles of buttons
				options[0]				   
				); //default button title
		
		setScore(initscore);
		System.out.println("Score: " + initscore);
	}
}
